#ifdef ARCTIC
#include "sal.h"
#include "dal.h"
#include "sys_usw_common.h"
#include "sys_usw_wb_common.h"

int32
sys_at_register_get_glb_acl_table(uint8 lchip, uint8 dir, sys_register_glb_acl_lkup_t* p_glb_acl_lkup)
{
    if (dir == CTC_INGRESS)
    {
        p_glb_acl_lkup->table_id            = IpeFwdAclCtl2_t;
        p_glb_acl_lkup->field_enable        = IpeFwdAclCtl2_gGlbAcl_0_aclEnable_f;
        p_glb_acl_lkup->field_label         = IpeFwdAclCtl2_gGlbAcl_0_aclLabel_f;
        p_glb_acl_lkup->field_lkup_type     = IpeFwdAclCtl2_gGlbAcl_0_aclLookupType_f;
        p_glb_acl_lkup->field_gport_type    = IpeFwdAclCtl2_gGlbAcl_0_aclGlobalPortType_f;
        p_glb_acl_lkup->field_use_pi_vlan   = IpeFwdAclCtl2_gGlbAcl_0_aclUsePIVlan_f;
    }
    else
    {
        p_glb_acl_lkup->table_id            = EpeAclQosCtl2_t;
        p_glb_acl_lkup->field_enable        = EpeAclQosCtl2_gGlbAcl_0_aclEnable_f;
        p_glb_acl_lkup->field_label         = EpeAclQosCtl2_gGlbAcl_0_aclLabel_f;
        p_glb_acl_lkup->field_lkup_type     = EpeAclQosCtl2_gGlbAcl_0_aclLookupType_f;
        p_glb_acl_lkup->field_gport_type    = EpeAclQosCtl2_gGlbAcl_0_aclGlobalPortType_f;
        p_glb_acl_lkup->field_use_pi_vlan   = EpeAclQosCtl2_gGlbAcl_0_aclUsePIVlan_f;
    }
    return CTC_E_NONE;
}

STATIC uint32
sys_pp_bmp_hash_make(sys_com_entry_hash_t* p_node)
{
    return p_node->id;
}

STATIC bool
sys_pp_bmp_hash_compare(sys_com_entry_hash_t* p_node0, sys_com_entry_hash_t* p_node1)
{
    return (p_node0->id == p_node1->id);
}

STATIC int32
sys_pp_bmp_free_node_data(void* node_data, void* user_data)
{
    if (node_data)
    {
        mem_free(node_data);
    }
    return CTC_E_NONE;
}

void*
sys_at_com_lookup_pp_bmp_hash(void* user_data, uint32 entry_id)
{
    ctc_hash_t* p_hash = (ctc_hash_t*)user_data;
    sys_com_entry_hash_t* p_node = NULL;
    sys_com_entry_hash_t  temp_pp_bmp = {entry_id, 0};

    p_node = ctc_hash_lookup(p_hash, &temp_pp_bmp);

    return p_node;
}

int32
sys_at_com_add_pp_bmp_hash(uint8 lchip, uint32 mem_mode, void* user_data, uint32 entry_id, uint16 pp_bmp)
{
    sys_com_entry_hash_t* p_node = NULL;
    ctc_hash_t* p_hash = (ctc_hash_t*)user_data;

    p_node = mem_malloc(mem_mode, sizeof(sys_com_entry_hash_t));

    if (NULL == p_node)
    {
        return CTC_E_NO_MEMORY;
    }
    p_node->id = entry_id;
    p_node->pp_bmp = pp_bmp;
    ctc_hash_insert(p_hash, p_node);

    return CTC_E_NONE;
}

int32
sys_at_com_remove_pp_bmp_hash(uint8 lchip, void* user_data, void* node)
{
    ctc_hash_t* p_hash = (ctc_hash_t*)user_data;
    sys_com_entry_hash_t* p_node = (sys_com_entry_hash_t*)node;

    ctc_hash_remove(p_hash, p_node);
    mem_free(p_node);
    p_node = NULL;

    return CTC_E_NONE;
}

int32
sys_at_com_remove_pp_bmp_hash_by_entry_id(uint8 lchip, void* user_data, uint32 entry_id)
{
    sys_com_entry_hash_t pp_bmp_node;
    sys_com_entry_hash_t* p_node = NULL;
    ctc_hash_t* p_hash = (ctc_hash_t*)user_data;
    pp_bmp_node.id = entry_id;

    p_node = ctc_hash_remove(p_hash, &pp_bmp_node);
    if (p_node)
    {
        mem_free(p_node);
    }

    return CTC_E_NONE;
}

void*
sys_at_com_entry_hash_init(uint8 lchip, uint32 entry_num, uint32 block_size)
{
    return ctc_hash_create(entry_num / block_size,block_size,
                    (hash_key_fn)sys_pp_bmp_hash_make,
                    (hash_cmp_fn)sys_pp_bmp_hash_compare);
}

int32
sys_at_com_entry_hash_deinit(uint8 lchip, void* user_data)
{
    ctc_hash_t* entry = (ctc_hash_t*)user_data;
    ctc_hash_free2(entry,(hash_traversal_fn)sys_pp_bmp_free_node_data, NULL);
    return 0;
}

#endif

